/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package metro.jme.lottery.graphics.screens;

import java.io.IOException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.StringItem;
import metro.jme.lottery.main.LotteryMIDlet;
import metro.jme.lottery.util.ImageHelper;

/**
 * Class displaying the about screen of the application
 * @author pierrej
 */
public class AboutScreen extends Form implements CommandListener {

	public static final String CONTENT = "Application developped for the J2ME course.";
	public static final String COPYRIGHT = "Software distributed under WTFPL license";
	public static final String AUTHOR = "Pierre JAMBET, pierre[dot]jambet{at}gmail(dot)com";
	public static final String VERSION = "1.0a";
	public static final String PLATFORM = "JME SDK 3.0, CLDC-1.1, MIDP-2.1, Mobile Media API 1.2, Wireless Messaging 1.1";
	
	private Command m_backCmd;
	private Command m_licenseCmd;
	
	private LotteryMIDlet m_lotteryMIDlet;
	private Displayable previousScreen;
	
	public AboutScreen(LotteryMIDlet m, Displayable d) {
		super("Metropolia Lottery Checker");
		
		m_lotteryMIDlet = m;
		previousScreen = d;
		
		m_backCmd = new Command("Back", Command.BACK, 1);
		m_licenseCmd = new Command("License", Command.SCREEN, 1);
		
		this.addCommand(m_licenseCmd);
		this.addCommand(m_backCmd);
		
		StringItem si = new StringItem("About", CONTENT, StringItem.PLAIN);
		Font font = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
		si.setFont(font);
		this.append(si);
		si = new StringItem("Copyright", COPYRIGHT, StringItem.PLAIN);
		si.setFont(font);
		this.append(si);
		si = new StringItem("Author", AUTHOR, StringItem.PLAIN);
		si.setFont(font);
		this.append(si);
		si = new StringItem("Version", VERSION, StringItem.PLAIN);
		si.setFont(font);
		this.append(si);
		si = new StringItem("Platform", PLATFORM, StringItem.PLAIN);
		si.setFont(font);
		this.append(si);
		
		try {
			Image logo = Image.createImage(
					ImageHelper.getOptimalImage("/imgs/logo.png", getWidth()));
			this.append(logo);
		} catch (IOException e) {
			//TODO: add an alert, explaining the error
			e.printStackTrace();
		}
		
	}

	public void commandAction(Command cmnd, Displayable dsplbl) {
		if(cmnd == m_backCmd) {
			m_lotteryMIDlet.displayNewScreen(previousScreen);
		} else if(cmnd == m_licenseCmd) {
			License l = new License(m_lotteryMIDlet, this);
			l.setCommandListener(l);
			m_lotteryMIDlet.displayNewScreen(l);
		}
	}
}
